package io.xccit.hotelsystem.ui.order;

import android.content.Context;
import android.database.Cursor;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import io.xccit.hotelsystem.utils.SQLiteHelper;

/**
 * 订单ViewModel
 */
public class OrderViewModel extends ViewModel {

    private final MutableLiveData<String> mText;
    private final MutableLiveData<Cursor> mOrders;
    private SQLiteHelper dbHelper;
    private Context context;

    public OrderViewModel() {
        mText = new MutableLiveData<>();
        mOrders = new MutableLiveData<>();
    }

    public OrderViewModel(Context context) {
        this.context = context;
        dbHelper = new SQLiteHelper(context);
        mText = new MutableLiveData<>();
        mOrders = new MutableLiveData<>();
    }

    public LiveData<String> getText() {
        return mText;
    }
    
    public LiveData<Cursor> getOrders() {
        return mOrders;
    }
    
    public void loadUserOrders(String username) {
        if (dbHelper != null) {
            Cursor cursor = dbHelper.getUserOrders(username);
            mOrders.postValue(cursor);
        }
    }
}